home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
364_01
/
glob_ca.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-24
|
27KB
|
1,023 lines
/*
HEADER: ;
TITLE: C-ACROSS;
VERSION 1.02
DESCRIPTION: "Utility for multiple module programs. Produces
Six indexes of functions, prototypes, and globals that
enable user to 'see across' modules for use in checking
and comparison. One of these is type of hierarchical
functions list, a listing by module of functions
and calls made FROM them; another is alphabetical list
of functions and calls made TO them. Globals listed
in schematic descriptors which record all modifiers
and qualifiers and enable checking of declarators
across modules. Creates, on request, header file
consisting of prototypes constructed from function
definitions. Can list user types #defined and some
preprocessor #defines. Full documentation in README.CA";
KEYWORDS: Utility, Cross Reference, Deubgging;
SYSTEM: MS-DOS;
FILENAME: GLOB_CA.C;
WARNINGS: "1. Assumes function definitions conform with
ANSI standards and have prototype form. See
also "Caveats and Restrictions" in README.CA.
2. Assumes syntactically correct source files.
3. Written and tested using Microsoft QuickC.
4. Copyright retained. See Copyright
information in README.CA.";
SEE-ALSO: EXIT_CA.C, GLOB_CA.C, FUNC_CA.C, IFDEF_CA.C, INTF_CA.C,
LINKL_CA.C, PARSE_CA.C, TDEF_CA.C, TYPES_CA, UTIL_CA.C,
UTLG_CA.C, XRF_CA.C, README.CA,
CA.H, CA.PRJ, CA.RPT, CDECL_CA.H, KEYWORDS.H;
AUTHORS: Myron Turner;
COMPILERS: Microsoft C;
*/
/*************************** C-ACROSS ***************************
V. 1.02
Copyright (C) Myron Turner
333 Bartlet Ave.
Winnipeg, Manitoba
Canada R3L 0Z9
(204) 284-8387
********************************************************************/
/*lint -esym(534,storage_class,process_vars) */
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <ctype.h>
#define EXTERNAL
#define INCLUDEFILES_DEFINE
#define TYPEDEF_DEFINE
#define TDEF_EXTERNAL
#include "ca.h"
#include "ca_decl.h"
#include "keywords.h"
static void glob_ca_msgs(int Line, char * Mod, struct func *func_top );
/* externs */
extern struct includeFILE inclF;
extern struct func *FirstFunction;
extern int function_no;
extern int reading_includeF;
extern int __mods[_MAX_MODS];
extern FILE *scrn_out;
extern int IfDefOFF;
extern char *CurrentMod;
/* globals */
struct globals_list *global = NULL, *globals_start = NULL;
char STRUNbuf[32];
#define SEMI_COLON (int) ';'
#define OPEN_PAREN (int) '('
#define CLOSE_PAREN (int) ')'
#define CLOSE_BRACKET (int) '}'
#define OPEN_BRACKET '{'
#define PROTOTYPE OPEN_PAREN
#define COMPLEX_DECL CLOSE_PAREN
#define inSTRUCTUNION -1
#define TYPEDEF_OPEN TYPEDEF + 101
#define INCLUDEFILE 1
#define COMPLEX_INI -1
#define conv_sign_type(s,t) { s = (char)((t & 0xFF00) >> 8); \
t = (t & 0x00FF); }
#define is_outsideFunction(n) ((n < func_top->line_no) \
|| (n > func_top->endfunc_line ))
static char COMPLEXdeclbuf[60];
static int COMPLExp = COMPLEX_INI;
static int in_structunion = 0;
static struct func * FN_ALPHAtop;
extern int In_MainLoop;
extern FILE **FP_ADDRESS;
extern unsigned int inclfLine;
extern unsigned int inclFini;
#define DEBUG_LINE 20
struct func * record_variables(FILE *fp, FILE *rptfp,
struct func *start, struct func **func_alphatop)
{
char storage, *p, *end_statement, buffer[261];
static struct func *func_top = NULL;
static struct func *previous = NULL;
unsigned line_num = 0, lineno;
int inquotes = 0, intypedf = 0, t_pos = 0, delim = 0;
int preproc_type, skip_ifdef = 0;
int next_statement = 0, split_line = 0, __type = NO_TYPE;
FILE * hold_fp = fp;
char *in_comment = NULL;
FP_ADDRESS = &fp;
rewind(fp); In_MainLoop = 0;
FN_ALPHAtop = NULL;
if(!func_top) func_top = FirstFunction;
else func_top = start->next_function;
if(func_top && func_top->fnptr) func_top = skip_fnptrs(func_top);
glob_ca_msgs( __LINE__, __FILE__, func_top );
ini_if_def_stack();
start_GlobalsLoop:
while ( fgets (buffer, 160, fp) )
{
if (!reading_includeF) lineno = ++line_num;
else lineno = ++inclfLine;
p = buffer;
if(line_num == DEBUG_LINE)
line_num = DEBUG_LINE;
if (in_comment) {
in_comment = is_closed_comment(p);
if (in_comment == (char *) scrn_out) {
in_comment = comment_error(func_top, lineno, p);
}
}
else in_comment = is_comment(p);
if(func_top)
{
if (is_outsideFunction(line_num) )
{
next_statement = is_nextstatement(&p); /* if not blank line */
while (next_statement)
{
do {
if ( (inquotes = isliteral(p)) ) p++;
if (*p == '\n') { next_statement = 0; break; }
} while (inquotes );
while (iswhite(*p)) p++;
if ( (preproc_type = is_includeF(p, hold_fp)) == INCLUDEFILE)
break;
if (preproc_type == PREPROCESSOR)
if (!IfDefOFF) skip_ifdef = is_else_if(p, skip_ifdef);
if (skip_ifdef) { next_statement = 0; break; }
COMPLExp = COMPLEX_INI;
if( !(delim == PROTOTYPE || split_line) )
if (!intypedf && !isdelim(*p) )
if (in_structunion || (t_pos = data_type_(p, &__type) )) {
if (__type != NO_TYPE ) {
char *complex_p = p;
if(!intypedf && !in_structunion) complex_p += t_pos;
delim = is_prototype(p);
if ( (delim != PROTOTYPE) ||
(delim == PROTOTYPE &&
(COMPLExp = is_complex_decl(complex_p))) ) {
t_pos = sign_or_ld(p, t_pos, &__type);
process_vars(p, t_pos, func_top, __type, lineno,
storage=0, rptfp);
}
}
}
else if (__type == TYPEDEF_OPEN) intypedf = 1;
if(!t_pos && __type != PREPROCESSOR) {
if (!intypedf && !in_structunion) {
if (!vol_const(p, func_top, lineno, &__type, rptfp))
delim = storage_class(p, func_top, lineno, &__type, rptfp);
}
}
if (next_statement)
{
next_statement = 0;
end_statement = strchr(p, SEMI_COLON);
if (end_statement || __type == PREPROCESSOR) {
intypedf = 0;
delim = 0;
split_line = 0;
if (end_statement) {
p = end_statement + 1;
next_statement = is_nextstatement(&p);
}
}
else
if (!intypedf && !in_structunion)
split_line = 1;
}
} /* while (next_statement) */
} /* if (is_outsideFunction(line_num)) */
else
storage_class(p, func_top, lineno, &__type, rptfp);
if (line_num >= func_top->endfunc_line) {
previous = func_top;
func_top = func_top->next_function;
}
} /* if (func_top) */
} /* while (fgets. . .) */
next_statement = 0;
end_statement = NULL;
intypedf = 0;
delim = 0;
split_line = 0;
if (close_include(hold_fp, &fp, rptfp, CurrentMod))
goto start_GlobalsLoop;
free_if_def_stack();
func_top = previous;
if (FN_ALPHAtop) *func_alphatop = FN_ALPHAtop;
return(previous);
}
static int xt_struct_union(char *p, int __type)
{
char *ptr = NULL;
char *initializing = NULL;
static char *close_brackets = NULL;
static char *open_brackets = NULL;
static char *ending_semicol = NULL;
static int identified = 0;
size_t count;
if (ending_semicol) {
in_structunion = 0;
open_brackets = NULL;
close_brackets = NULL;
ending_semicol = NULL;
}
initializing = strchr(p, '=');
if (initializing) {
*initializing = ';';
*(++initializing) = '\0';
}
if(!open_brackets) {
open_brackets = strchr(p, (int) OPEN_BRACKET);
if(open_brackets) in_structunion = 1;
}
if (open_brackets && !close_brackets)
close_brackets = strchr(p, CLOSE_BRACKET);
if (close_brackets && !ending_semicol) {
ending_semicol = strchr(p, SEMI_COLON);
}
if (in_structunion && !close_brackets) {
if (!identified) { isolate_strun(p, __type); identifie